package shopping.stock.call.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@Slf4j
@RestController
public class OrderController {
  
  @Autowired
  private RestTemplate restTemplate;
  
  @GetMapping("/order/create/{productId}")
  public String createOrder(@PathVariable("productId") Integer productId) {
    String result = restTemplate.getForObject("http://shopping-stock/stock/reduce/" + productId, String.class);
    log.info("进行减库存: {}", result);
    return result;
  }
}
